package cn.yunwei.module.controller.admin.user;

import cn.yunwei.module.controller.admin.user.vo.UserCreateReqVO;
import cn.yunwei.module.dal.dataobject.user.SystemUser;
import cn.yunwei.module.pojo.CommonResult;
import cn.yunwei.module.service.UserService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import static cn.yunwei.module.pojo.CommonResult.success;

/**
 * @author wangbinggui
 */
@Tag(name = "用户管理")
@RequestMapping("/admin-api/user")
@RestController
@Validated
public class UserController {
    /**
     * 实现用户添加
     */
    @Resource
    private UserService userService;

    @PostMapping("/add")
    @Operation(summary = "新增用户")
    @ApiOperationSupport(author = "xxxx")
    public CommonResult<Long> addUser(@RequestHeader("X-Custom-Header") String customHeader, // 强制要求请求头
                                     @Valid @RequestBody UserCreateReqVO userCreateReqVO) {
        return success(userService.addUsers(userCreateReqVO));
    }

    @GetMapping("/query")
    @Operation(summary = "根据用户ID查询用户")
    @ApiOperationSupport(author = "xxxx")
    public CommonResult<SystemUser> queryUserById(@RequestHeader("X-Custom-Header") String customHeader,
                                                    @RequestParam("id") Long id) {
        SystemUser user = userService.queryUser(id);
        return success(user);
    }
}
